package edu.kit.csl.cratyli.control;

import edu.kit.csl.cratyli.datatypes.BadParameterValueException;
import edu.kit.csl.cratyli.datatypes.Dictionary;
import edu.kit.csl.cratyli.datatypes.TextCorpus;
import edu.kit.csl.cratyli.ui.Configuration;

/**
 * A combination strategy decides how to combine text corpora. It also
 * may update the dictionary if two words of the text corpora are merged
 * together.
 */
public abstract class CombinationStrategy {
	
	/**
	 * Merger which should be used by subclasses to merge a set of words.
	 */
	protected Merger merger;
	
	/**
	 * Sole constructor. Initializes the merger.
	 */
	public CombinationStrategy() throws BadParameterValueException {
		String m = Configuration.getSingleton()
				.getString("merger");
		if (m.equals("srilm")) {
			merger = new SrilmMerger();
		} else if (m.equals("maximum")) {
			merger = new MaximumMerger();
		} else {
			throw new BadParameterValueException(
					"Merger not known");
		}
	}

	/**
	 * Merges two text corpora and updates the dictionary accordingly.
	 * 
	 * @param dict Dictionary containing words of both corpora
	 * @param primary the primary text corpus
	 * @param secondary the secondary text corpus
	 * @return the merged text corpus
	 * @throws NullPointerException if one of the parameters is null
	 */
	abstract public TextCorpus combine(Dictionary dict, TextCorpus primary,
			TextCorpus secondary);
}
